package com.android.boncen.commonFrame.user;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.android.boncen.commonFrame.R;
import com.android.boncen.commonFrame.adapter.ConllectionDocAdapter;
import com.android.boncen.commonFrame.adapter.DocAdapter;
import com.android.boncen.commonFrame.bean.CollectionBean;
import com.android.boncen.commonFrame.bean.UserBean;
import com.android.boncen.commonFrame.tools.DesityUtil;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * 功能描述:以及我的医生（显示我收藏过的医生）ok
 *
 * @date 2017/2/9
 */

public class CollectionFragment extends Fragment {

    private ListView lvList;
    private ConllectionDocAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.comm_list_layout,container,false);
        lvList = (ListView) view.findViewById(R.id.lvList);
        return  view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        adapter =new ConllectionDocAdapter(getContext());
        lvList.setAdapter(adapter);
        getDoc();
    }

    public void getDoc()
    {
        BmobQuery<CollectionBean> query = new BmobQuery<CollectionBean>();
        UserBean user = BmobUser.getCurrentUser(UserBean.class);
        query.addWhereEqualTo("deviceId",user.getObjectId());    // 查询当前用户的所有
        query.order("-updatedAt");
        query.include("doc");
        query.findObjects(new FindListener<CollectionBean>() {

            @Override
            public void done(List<CollectionBean> object, BmobException e) {
                if(e==null){
                    adapter.setData(object);
                }else{

                }
            }

        });
    }
}
